package com.itheima.mapper;

import com.itheima.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author hu
 * @date 2025/1/29
 */
@Mapper
public interface DeptMapper {


    @Results({
        @Result(column = "create_time",property = "createTime"),
        @Result(column = "update_time",property = "updateTime")
    })
//    @Select("select id, name, create_time createTime, update_time updateTime from dept order by update_time desc ")
    @Select("select id, name, create_time , update_time from dept order by update_time desc ")
    List<Dept> listAll();

    @Delete("delete from dept where id = #{id}")
    void deleteById(Integer id);

//    @Insert("insert into dept (id, name, create_time, update_time) values (null,#{name},now(),now())")
    @Insert("insert into dept (name, create_time, update_time) values (#{name},#{createTime},#{updateTime})")
    void addDept(Dept dept);

    @Update("update dept set name = #{name} where id = #{id}")
    void updateDept(Dept dept2);

    @Select("select id, name, create_time, update_time from dept where id = #{csss}")
//    @Select("select id, name, create_time, update_time from dept where id = #{id}")
    Dept selectDeptById(Integer csid); //这里是形参写什么都可以的。加@param是针对两个及以上形参mybatis无法识别才加的给起名字
//    Dept selectDeptById(@Param("id") Integer csid);
    //对于MyBatis的SQL映射语句，如 @Select("select id, name, create_time, update_time from dept where id = #{id}")，
    // MyBatis会根据SQL语句中的占位符（如#{id}）来匹配方法参数。
    // 即使方法参数名为csid，MyBatis也会正确地将csid的值绑定到SQL语句中的#{id}




}
